package com.yc.jpyy.terminator.controller;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.config.Config;
import com.yc.jpyy.base.controller.BaseController;
import com.yc.jpyy.mobile.dao.BizDao;
import com.yc.jpyy.mobile.service.BizService;

@Controller
@RequestMapping(value = "/terminator")
public class StudentInfoController extends BaseController{
	
	//private static Logger logger = LoggerFactory.getLogger(StudentInfoController.class);	
	@Autowired
	private BizService bizService;

	@Autowired
	private BizDao bizDao;
	
	/**
	 *2.3	学员基本信息获取
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/GetStudentInfo", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String GetStudentInfo(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		try {

			// 学员手机号
			String Mobilephone = request.getParameter("Mobilephone")==null?"":request.getParameter("Mobilephone");
			
			//区别访问标志
			String diffMark = request.getParameter("diffMark");
			if(diffMark!=null&&!diffMark.isEmpty())
			{
				String imgUrl = Config.getImageAddress();
				Map<String, Object> valMap = new HashMap<String, Object>();
				valMap.put("imgUrl", imgUrl);
				valMap.put("diffMark", diffMark);
				valMap.put("Mobilephone", Mobilephone);
				List<Map<String, Object>> stumap=bizDao.getStudentInfoForTerminater(valMap);
				if (stumap != null && stumap.size() > 0) {
					response.setData(stumap);
				}else {
					response.setErrorcode(1);
					response.setMessage("该学员无基本信息...");
				}
			}else
			{
				response.setErrorcode(1);
				response.setMessage("区别访问标志不能为空...");
			}
				
		} catch (Exception e) {
			System.out.println("GetStudentInfo:"+ e.toString());
			response.setReturnMsg(1,"学员基本信息获取失败！");
		} finally {
			return response.toJSON();
		}
	}
	
	
	/**
	 * 2.4	学员学时信息
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/GetStudyTimeQuery", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String GetStudyTimeQuery(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		try {

			//学员全国编号
			String Stunum = request.getParameter("Stunum");
			//科目编号
			String Subject = request.getParameter("Subject");
			if(Stunum!=null&&!Stunum.isEmpty() && Subject!=null&&!Subject.isEmpty())
			{
				
				List<Map<String, Object>> stumap=bizDao.getStudyTimeQueryForTerminater(Stunum, Subject);
				if (stumap != null && stumap.size() > 0) {
					 
					// 设置Json集合
					response.setData(stumap);
				} else {
					response.setErrorcode(1);
					response.setMessage("该学员无学时信息...");
				}
			}
			else
			{
				response.setErrorcode(1);
				response.setMessage("学员全国编号、科目编号不能为空...");
			}

		} catch (Exception e) {
			System.out.println("GetStudyTimeQuery:"+ e.toString());
			response.setReturnMsg(1,"获取学员学时信息失败！");
		} finally {
			return response.toJSON();
		}
	}
	
	/**
	 * 2.6	电子教学日志
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/GetStudyRecordResult", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String GetStudyRecordResult(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();
		request.setCharacterEncoding("UTF-8");

		try {

			//学员全国编号
			String Stunum = request.getParameter("Stunum");
			
			if(Stunum!=null&&!Stunum.isEmpty())
			{
				
				List<Map<String, Object>> stumap=bizDao.getStudyRecordResultForTerminater(Stunum);
				if (stumap != null && stumap.size() > 0) {
					 
					// 设置Json集合
					response.setData(stumap);
				} else {
					response.setErrorcode(1);
					response.setMessage("该学员无电子教学日志...");
				}
			}
			else
			{
				response.setErrorcode(1);
				response.setMessage("学员全国编号不能为空...");
			}

		} catch (Exception e) {
			System.out.println("GetStudyRecordResult:"+ e.toString());
			response.setReturnMsg(1,"获取学员电子教学日志失败！");
		} finally {
			return response.toJSON();
		}
	}
}
